<template>
	<view>
		<view v-if="err">
			{{err}}
		</view>
		<view style="padding: 30rpx;">
			<u-button type="primary" @click="savePDF">保存到本地</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: null,
				tempFilePath:null,
				err:null
			}
		},
		onLoad(options) {
			var that = this;
			console.log(options);
			if (options.url) {
				// this.url=options.url;
				uni.downloadFile({
					url: options.url,
					success(res) {
						console.log(res);
						that.tempFilePath=res.tempFilePath;
						uni.openDocument({
							showMenu: true,
							filePath: res.tempFilePath
						})
					},
					fail(com) {
						that.err=JSON.stringify(com)
					}
				})
			}
		},
		methods: {
			savePDF() {
				var that = this;
				uni.saveFile({
					tempFilePath: that.tempFilePath,
					success: function(res) {
						var savedFilePath = res.savedFilePath;
						uni.showToast({
							title:'已保存至 '+ savedFilePath
						})
					}
				});
			}
		}
	}
</script>

<style>

</style>